package com.ggg.clothesshop.controller;


import com.ggg.clothesshop.model.Product;
import com.ggg.clothesshop.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/product")
public class ProductController {

    @Autowired
    ProductService productService;

    //获取一页产品的信息
    @ResponseBody
    @RequestMapping("/selectByPage")
    public Object selectByPage(
            @RequestParam(name = "pageNum", required = false, defaultValue = "1")
                    int pageNum,
            @RequestParam(name = "pageSize", required = false, defaultValue = "12")
                    int pageSize,
            @RequestParam(name = "attributeValue", required = false, defaultValue = "xxx")
                    String attributeValue){

        return productService.selectByPage(pageNum,pageSize,attributeValue);
    }

    //获取所有产品的信息
    @ResponseBody
    @RequestMapping("/selectAll")
    public Object selectAll(){

        return productService.selectAll();
    }


    //获取一个产品的详细信息
    @ResponseBody
    @RequestMapping("/selectById")
    public Product selectById(String productId){
        Product product = productService.selectById(productId);
        return product;
    }
}
